package com.xing.security;

import com.xing.service.SysUserDetailService;
import com.xing.user.UserDetail;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * @version 1.0
 * @Author Xing
 * @Date 2023/12/3 21:46
 */
@Service
@Slf4j
public class UserDetailsServiceImpl implements UserDetailsService {

    @Autowired
    private SysUserDetailService sysUserDetailService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        log.info("测试01"+username);
        UserDetail userDetail = null;
        try {
            userDetail = sysUserDetailService.getUserDetailByUsername(username);
            log.info("测试02");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        if (userDetail == null) {
            log.warn("UserDetailService.loadUserByUsername:用户为空");
        }

        return userDetail;
    }
}
